<template>
  <div></div>
</template>

<script>
import Setting from '@/setting.js'
import { SystemLogin, getUserLogin } from '@/api/system/login'
import util from '@/libs/util'
export default {
  name: 'allView',
  props: {},
  components: {},
  data() {
    return {}
  },
  methods: {
    getExpiresTime(expiresTime) {
      let nowTimeNum = Math.round(new Date() / 1000)
      let expiresTimeNum = expiresTime - nowTimeNum
      return parseFloat(parseFloat(parseFloat(expiresTimeNum / 60) / 60) / 24)
    },
    tapCaptchas: function () {
      this.verifyImg =
        Setting.apiBaseURL +
        '/systemv1/login/captcha?visitorId=' +
        this.visitorId +
        '&_t=' +
        this.$utils.strtotime()
    },
  },
  mounted() {},
  watch: {},
  computed: {},
  filters: {},
  async created() {
    const urlParams = new URLSearchParams(window.location.search)
    // console.log(urlParams);
    const id = urlParams.get('id') // value1
    // console.log(id);
    const res2 = await getUserLogin({
      id,
    })
    localStorage.setItem('nanxun_zhifa_id', res2.data.id)
    SystemLogin({
      username: id ? res2.data.username: 'superManageMent',
      password: id ? atob(res2.data.password) : '@Ss123456',
      captcha: '1',
    })
      .then(async (res) => {
        this.isLogin = false
        if (res.code == 200) {
          let expires = this.getExpiresTime(res.data.expires_time)
          // 记录用户登陆信息
          util.cookies.set('system_uuid', res.data.user_info.id, {
            expires: expires,
          })
          //用户token
          util.cookies.set('system_token', res.data.token, {
            expires: expires,
          })
          //过期时间
          util.cookies.set('system_expires_time', res.data.expires_time, {
            expires: expires,
          })

          this.$store.dispatch('system/menu/set', res.data.menus)
          this.$store.dispatch('system/user/set', res.data.user_info)
          this.$store.dispatch('system/user/setpaths', res.data.paths)

          this.$router.push({
            path: '/system/index',
            query: {
              identity: id ? res2.data.id : 'superManageMent',
            },
          })
        } else {
          this.tapCaptchas()
          this.$Message.error(res.msg || '登录失败')
        }
      })
      .catch((err) => {
        let data = err === undefined ? {} : err
        this.isLogin = false
        this.tapCaptchas()
      })
  },
}
</script>

<style scoped lang="less"></style>
